import path from 'path'
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import vue from '@vitejs/plugin-vue'
import Unocss from 'unocss/vite'

export default defineConfig(({ command, mode }) => {
  let cfg = {
    resolve: {
      alias: {
        '~': path.resolve(__dirname, 'src/')
      }
    },
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver()]
      }),
      AutoImport({
        resolvers: [VantResolver()],
        imports: [
          'vue',
          'vue-router',
          'vue-i18n',
          {
            '~/store/app': ['useAppStore'],
            '~/utils/http': ['http', 'request'],
            '~/utils/util': [
              'debounce',
              'throttle',
              'numBits',
              'showSugar',
              'showCold',
              'orderType',
              'orderStatus',
              'orderStatusWithTime',
              'showName',
              'showAgentType'
            ],
            '~/api': ['apis'],
            '~/utils/page': ['useList'],
            '~/utils/cache': ['cache']
          }
        ],
        vueTemplate: true,
        dts: 'src/dts/auto-import.d.ts'
      }),
      Unocss()
    ],
    base: '/tea/',
    envDir: 'env/',
    server: { host: '0.0.0.0', port: 5172 }
  }

  return cfg
})
